/*
 * Customer.java
 *
 * Created on 27 March 2007, 11:45
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usyd.comp5348;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

/**
 * Entity class Customer
 *
 * @author Yuezhong Zhang
 */
@Entity(name="Customers")
public class Customer implements Serializable {
    
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO, generator="CusttIdSeq")
    @SequenceGenerator(name="CustIdSeq", sequenceName="cust_id_seq")
    private Integer id;
    
    /** Creates a new instance of Customer */
    public Customer() {
    }
    
    public Customer(CustomerInfo c) {
        setAddress(c.getAddress());
        if (c.getId() != CustomerInfo.UNDEFINED)
            setId(c.getId());
        setName(c.getName());
    }
    
    public CustomerInfo getCustomerInfo() {
        return new CustomerInfo(getId(), getName(), getAddress());
    }
    
    /**
     * Gets the id of this Customer.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }
    
    /**
     * Sets the id of this Customer to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }
    
    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
    
    /**
     * Determines whether another object is equal to this Customer.  The result is
     * <code>true</code> if and only if the argument is not null and is a Customer object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }
    
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "usyd.comp5348.entity.Customer[id=" + id + "]";
    }
    
    /**
     * Holds value of property name.
     */
    @Column(name="customer_name", nullable=false)
    private String name;
    
    /**
     * Getter for property customerName.
     * @return Value of property customerName.
     */
    public String getName() {
        return this.name;
    }
    
    /**
     * Setter for property customerName.
     * @param customerName New value of property customerName.
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * Holds value of property address.
     */
    @Column(name="address", nullable=false)
    private String address;
    
    /**
     * Getter for property address.
     * @return Value of property address.
     */
    public String getAddress() {
        return this.address;
    }
    
    /**
     * Setter for property address.
     * @param address New value of property address.
     */
    public void setAddress(String address) {
        this.address = address;
    }
    
}
